<%@ page import="com.ld.businesscard_manage.bean.User" %>
<%@ page import="java.util.List" %>
<%@ page import="com.ld.businesscard_manage.service.impl.UserServiceImpl" %>
<%@ page import="com.ld.businesscard_manage.service.UserService" %><%--
  Created by IntelliJ IDEA.
  User: 刘邓
  Date: 2023-06-10
  Time: 8:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户管理</title>
  <style>
    td {
      color: #ff4b2b;
      margin-left: 20px;
      text-align: center;
    }
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }
    a {
      text-decoration: none;
      color: black;
    }
    .container {
      background-color: #fff;
      border-radius: 10px;
      box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35), 0 10px 10px rgba(0, 0, 0, 0.22);
      position: relative;
      overflow: hidden;
      width: 768px;
      max-width: 100%;
      min-height: 480px;
      margin:0 auto;
    }
  </style>
</head>
<body>
<%!
  private UserService userService= new UserServiceImpl();
%>
<%
  List<User> users = userService.getAllUsers();
  out.println("<a href='/home/manage.jsp' style='display: inline-block;width:30%,height: 30px;margin:10px 30px;text-align:center;line-height:30px;background-color:blue'>返回管理页面</a><br>");
  out.println("<a href='/home/addUser.jsp' style='display: inline-block;width:30%,height: 30px;margin:10px 30px;text-align:center;line-height:30px;background-color:orange'>添加用户</a><br>");
  if (users.isEmpty()) out.println("<h1 style='width: 80%;height:400px;margin: 0 auto;text-align:center;line-height:400px'>暂无更多信息!<h1>");
  else {
    out.println("<table class='container'>" +
            "<tr>" +
            "<th>id</th>" +
            "<th>用户名</th>" +
            "<th>密码</th>" +
            "<th>修改</th>" +
            "<th>删除</th>" +
            "</tr>");
    if (!users.isEmpty())
      for (User user : users) {
        String changeDOM = "<td><a href=" + "'/home/changeUser.jsp?id=" + user.getId() + "'>修改" + "</a></td>";
        String deleteDOM = "<td ><a class='deleteUser' href=" + "'/home/deleteUser.jsp?id=" + user.getId() + "'>删除" + "</a></td>";
        out.println("<tr>");
        out.println("<td style='text-align:center'>" + user.getId() + "</td>");
        out.println("<td style='text-align:center'>" + user.getUsername() + "</td>");
        out.println("<td style='text-align:center'>" + user.getPassword() + "</td>");
        out.println(changeDOM);
        out.println(deleteDOM);
        out.println("</tr>");
      }
    out.println("</table>");
  }
%>
</body>
<script>
  let deleteU = document.getElementsByClassName("deleteUser");
  for (let i = 0; i < deleteU.length; i++) {
    deleteU[i].addEventListener("click",(e) => {
      var b = confirm("你确定要删除吗?");
      if(b == false){
        e.preventDefault();
      }
    })
  }
</script>
</html>
